// 截取到地址栏的ID和商品名 来进行网页dom显示
const goodsId = getUrlParam("id")
const goodsName = decodeURIComponent(getUrlParam("goodsName"))//转码
console.log(goodsName);

// 从登录页的cookie获取需要传递的参数：userId
let nickname = getCookie("nickname") ? JSON.parse(getCookie("nickname")) : null;
if (nickname) {
    //    userId
    let userId = nickname.id;
    console.log(userId);//2915
} 
// 截取地址栏的userId
const userId = getUrlParam("userId");
console.log(userId);


ajax({
    url: "http://phpclub.org.cn:8080/api/cart/add",
    type: 'post',
    data: {
        // userId   goodsId   goodsCount三个请求参数
        goodsId: goodsId,
        // goodsName: goodsName,
        userId:nickname.id,
        goodsCount:1
    },
    success: function (response) {
        // console.log(goodsId);
        console.log(response.data);
        document.querySelector(".left").innerHTML = `
          <div class="success"><img src="./img/success.png" alt=""></div>
              <div class="text">
                  <p class="successText">已成功加入购物车！</p>
                  <span class="goodsName" >${goodsName}</span>
              </div>`

        // 返回上一页面
        document.querySelector(".return").onclick = function () {
            window.history.back();
        }
        // 点击跳转去购物车结算

        document.querySelector(".clearCart").href =`cart.html?userId=${userId}`

    }
})




